package com.solvePlat.controller;

import com.github.pagehelper.PageInfo;
import com.solvePlat.entity.WorkInfo;
import com.solvePlat.entity.WorkInfoExtend;
import com.solvePlat.entity.base.BaseResponse;
import com.solvePlat.service.WorkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/workInfo")
public class WorkInfoController {
    @Autowired
    private WorkInfoService workInfoService;

    @PostMapping("/selectWorkInfo")
    public BaseResponse<PageInfo>  selectWorkInfo(@RequestBody WorkInfo workInfo){
        PageInfo pageInfo = workInfoService.selectWorkInfoByPage(workInfo);
        return new BaseResponse<PageInfo>(true, "查询成功!",pageInfo );
    }

    @PostMapping("/saveWorkInfo")
    public BaseResponse saveArticleInfo(@RequestBody WorkInfo workInfo) throws Exception {
        BaseResponse baseResponse = new BaseResponse();
        String uuid = workInfoService.saveWorkInfoReturnUuid(workInfo);
        baseResponse.setMsg("发布成功!");
        baseResponse.setData(uuid);
        baseResponse.setSuccess(true);
        return baseResponse;
    }

    @GetMapping("/getWorkInfo")
    public BaseResponse getWorkInfo(WorkInfo workInfo){
        BaseResponse<WorkInfoExtend> baseResponse = new BaseResponse<WorkInfoExtend>();
        WorkInfoExtend workInfoExtend = workInfoService.getWorkInfo(workInfo);
        baseResponse.setMsg("查询成功!");
        baseResponse.setData(workInfoExtend);
        baseResponse.setSuccess(true);
        return baseResponse;
    }

    @GetMapping("/addBrowseNum")
    public  BaseResponse addBrowseNum(WorkInfo workInfo){
        BaseResponse<String> baseResponse = new BaseResponse<String>();
        workInfoService.addBrowseNum(workInfo);
        baseResponse.setSuccess(true);
        baseResponse.setMsg("增加成功!");
        return baseResponse;
    }

    @GetMapping("/selectSelfWorkInfo")
    public BaseResponse selectSelfWorkInfo(WorkInfo workInfo){
        PageInfo pageInfo = workInfoService.selectSelfWorkInfo(workInfo);
        return new BaseResponse<PageInfo>(true, "查询成功!",pageInfo );
    }

    @GetMapping("/getRankingList")
    public BaseResponse getRankingList(WorkInfo workInfo){
        PageInfo pageInfo = workInfoService.getWorkInfoRankingList(workInfo);
        return new BaseResponse<PageInfo>(true, "查询成功!",pageInfo );
    }
}
